package bot.controller;

import bot.mapper.BlacklistMapper;
import bot.pojo.Blacklist;
import bot.pojo.BlacklistExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/blacklist")
public class blacklistController {//黑名单操作
    BlacklistExample blacklistExample = new BlacklistExample();
    @Autowired
    BlacklistMapper blacklistMapper;
    @GetMapping("/sendblacklist")
    public String sendblacklist(Long id,Long groupid){
        blacklistExample.clear();
        blacklistExample.createCriteria().andQqidEqualTo(String.valueOf(id)).andGroupidsEqualTo(String.valueOf(groupid));
        List<Blacklist> blacklists = blacklistMapper.selectByExample(blacklistExample);
        if(blacklists.size() > 0){//判断这人是否已被拉入黑名单
            return "false";
        }
        blacklistExample.clear();
        Blacklist blacklist = new Blacklist();
        blacklist.setQqid(String.valueOf(id));
        blacklist.setGroupids(String.valueOf(groupid));
        blacklistMapper.insert(blacklist);
        return "true";
    }
    @GetMapping("/isitablacklist")
    public String isitablacklist(Long id,Long groupid){
        blacklistExample.clear();
        blacklistExample.createCriteria().andQqidEqualTo(String.valueOf(id)).andGroupidsEqualTo(String.valueOf(groupid));
        List<Blacklist> blacklists = blacklistMapper.selectByExample(blacklistExample);
        if(blacklists.size() > 0){
            return "true";
        }
        return "false";
    }
}
